﻿using OCR.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OCR.SystemThread
{
    class CameraTriggerThread_ModbusRealTime
    {
        public static bool CameraTrigger_Flowrec = false;
        public static Thread CameraTriggerFlow_Thread = null;
        public static int iCameraTrigger_Step = 0;

        public static bool CameraTrigger_Stop = false;
        public static void CameraTrigger_Thread()
        {
            CameraTrigger_Flowrec = true;
            CameraTriggerFlow_Thread = new Thread(CameraTriggerFlowThread);
            CameraTriggerFlow_Thread.IsBackground = true;
            CameraTriggerFlow_Thread.Start();
        }

        private static void CameraTriggerFlowThread(object obj)
        {
            while (CameraTrigger_Flowrec)
            {
                switch (iCameraTrigger_Step)
                {
                    case 0:
                        //AlgorithmModule.ImageHandleV2_Refresh(Application.StartupPath + "\\TemplateInput\\Refresh.bmp");

                        break;
                    case 5:
                        //AlgorithmModule.ImageHandleV2_Refresh(Application.StartupPath + "\\TemplateInput\\Refresh.bmp");
                        if (CameraReceiveThread.isImageData)
                        {
                            DateTime imgDateTime = DateTime.Now;
                            Console.WriteLine("抓图时长: " + (imgDateTime - OCR_Form.grabImgTime).Milliseconds);
                            Console.WriteLine("已获取到图片信息");
                            //Console.WriteLine("frameForSave.Image0:  " + CameraReceiveThread.frameForSave.Image);
                            OCR_Form.oCR_Form.mainCameraPb.Image = CameraReceiveThread.frameForSave.Image.ToBitmap();
                            //AlgorithmModule.ImageHandleV2_OnceTri_Modbus();

                            CameraReceiveThread.isImageData = false;
                            CameraReceiveThread.frameForSave = null;

                            //iCameraTrigger_Step = 0;

                        }
                        //Thread.Sleep(2000);
                        //Console.WriteLine("2s无图");
                        //iCameraTrigger_Step = 0;
                        break;
                }
                Thread.Sleep(1);
            }
        }
    }
}
